<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const obj = {
      name: 'why',
      // 1.和hasOwnProperty的区别一: 防止对象中也有一个自己的hasOwnProperty方法
      // hasOwnProperty: function () {
      //   return "abc"
      // },
      age: 18,
      __proto__: {
        address: '广州市'
      }
    }
    console.log(obj.name, obj.age) // why 18
    console.log(obj.address) // 广州市
    console.log(obj.hasOwnProperty('name')) // true
    console.log(obj.hasOwnProperty('address')) // false

    console.log(Object.hasOwn(obj, 'name')) // true
    console.log(Object.hasOwn(obj, 'address')) // false

    // 2.和hasOwnProperty的区别二:
    const info = Object.create(null)
    info.name = "why"
    // console.log(info.hasOwnProperty("name"))
    console.log(Object.hasOwn(info, "name"))
  </script>
</body>

</html>